package com.ruoyi.mes.systembasic.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesDepartment;
import com.ruoyi.mes.systembasic.service.ISmesDepartmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间管理Controller
 *
 * @author simpsense
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/systembasic/department")
public class SmesDepartmentController extends BaseController
{
    @Autowired
    private ISmesDepartmentService smesDepartmentService;

    /**
     * 查询车间管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesDepartment smesDepartment)
    {
        startPage();
        List<SmesDepartment> list = smesDepartmentService.selectSmesDepartmentList(smesDepartment);
        return getDataTable(list);
    }

    /**
     * 导出车间管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:export')")
    @Log(title = "车间管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesDepartment smesDepartment)
    {
        List<SmesDepartment> list = smesDepartmentService.selectSmesDepartmentList(smesDepartment);
        ExcelUtil<SmesDepartment> util = new ExcelUtil<SmesDepartment>(SmesDepartment.class);
        return util.exportExcel(list, "department");
    }

    /**
     * 获取车间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:query')")
    @GetMapping(value = "/{departmentId}")
    public AjaxResult getInfo(@PathVariable("departmentId") Long departmentId)
    {
        return AjaxResult.success(smesDepartmentService.selectSmesDepartmentById(departmentId));
    }

    /**
     * 新增车间管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:add')")
    @Log(title = "车间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesDepartment smesDepartment)
    {
        return toAjax(smesDepartmentService.insertSmesDepartment(smesDepartment));
    }

    /**
     * 修改车间管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:edit')")
    @Log(title = "车间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesDepartment smesDepartment)
    {
        return toAjax(smesDepartmentService.updateSmesDepartment(smesDepartment));
    }

    /**
     * 删除车间管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:department:remove')")
    @Log(title = "车间管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{departmentIds}")
    public AjaxResult remove(@PathVariable Long[] departmentIds)
    {
        return toAjax(smesDepartmentService.deleteSmesDepartmentByIds(departmentIds));
    }
}